home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 8
/
QRZ Ham Radio Callsign Database - Volume 8.iso
/
pc
/
files
/
t_unix
/
bs941029.tgz
/
bbsx-941029.tar
/
bbsx
/
rerase.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-29
|
4KB
|
181 lines
#ifndef __lint
static char rcsid[] = "@(#) $Header: /home/dg1rtf/tcp/bbsx/RCS/rerase.c,v 1.1 1994/06/01 22:21:32 dg1rtf Exp $";
#endif
#define _HPUX_SOURCE
#include <stdio.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <pwd.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <termios.h>
#include <unistd.h>
#include "bbs.h"
#include "bbs.hd"
typedef struct BID_ENT {
int mesg ;
char bid[LEN_BID+1];
short del;
struct BID_ENT *next;
} BID_ENT;
extern optind;
extern char *optarg;
int err_flag;
const struct cmdtable cmdtable[1];
/* In rerase.c: */
int main(int argc, char **argv);
/*---------------------------------------------------------------------------*/
int main(int argc, char **argv)
{
short delete = 1; /* msgs werden geloescht */
short time_st = 1; /* Time_stamp wird geaendert */
short debug = 0; /* Debugging ist OFF */
char to[LEN_TO+1];
int c;
struct index index;
struct BID_ENT *bid_ent, first;
struct passwd *pw;
if (getuid()) {
pw = getpwnam(bbsadm);
if(getuid() != pw->pw_uid) {
perror("permission denied");
return 1;
}
}
if (chdir(WRKDIR)) {
mkdir(WRKDIR, 0755);
if(chdir(WRKDIR)) halt();
}
read_config();
bid_ent = &first;
bid_ent->next = (BID_ENT *) NULL;
while ((c = getopt(argc, argv, "r:abdrt")) != EOF)
switch (c) {
case 'd':
debug = 1;
break;
case 'a':
strcpy(to,"A");
delete = 0;
break;
case 'b':
strcpy(to,"B");
delete = 0;
break;
case 'r':
strcpy(to,strupc(optarg));
delete = 0;
break;
case 't':
time_st = 0;
break;
case '?':
err_flag = 1;
break;
}
if (optind < argc) err_flag = 1;
if (err_flag) {
puts("usage: rerase [-d] [-a|b|r dest] [-t]");
exit(1);
}
if ((fdindex = open(INDEXFILE, O_RDWR, 0644)) < 0) return 1;
for (; ; ) {
if (read(fdindex, (char *) &index, sizeof(index)) != sizeof(index)) goto stop_look;
if (!(index.flags & DELETED) && index.to[1]) {
bid_ent->mesg=index.mesg;
strcpy(bid_ent->bid,index.bid);
bid_ent->del=0;
if ((bid_ent->next = malloc(sizeof(BID_ENT))) == NULL) {
puts("not enought memory");
return 1;
}
bid_ent = bid_ent->next;
bid_ent->next = (BID_ENT *) NULL;
}
}
stop_look:
if (lseek(fdindex, 0L, SEEK_SET))
return 1;
for (; ; ) {
if (read(fdindex, (char *) &index, sizeof(index)) != sizeof(index)) goto stop_read;
if (!(index.flags & DELETED )) {
if (*index.to == 'E' && index.to[1] == 0 && !strcmp(index.at,"THEBOX")) {
bid_ent=&first;
while(bid_ent->next) {
if(!strcmp(bid_ent->bid,index.subject))
bid_ent->del=1;
bid_ent=bid_ent->next;
}
}
}
}
stop_read:
bid_ent=&first;
while(bid_ent->next) {
if(bid_ent->del) {
if (!get_index(bid_ent->mesg, &index)) {
if (debug)
printf("Error in indexfile: msg %d\n",bid_ent->mesg);
return 1;
}
if (time_st)
index.date=time((long *) 0);
if (delete) {
unlink(getfilename(bid_ent->mesg));
index.flags |= DELETED;
}
else {
strcpy(index.to,to);
strcpy(index.at,Myhostname);
}
if (debug) {
printf("msg: %d\t%s\t\tact. area: %s\tBID: %s\n",index.mesg,
index.flags & DELETED ? "deleted" : "moved",
index.to,index.bid);
}
if (lseek(fdindex, -sizeof(struct index), SEEK_CUR) < 0) return -1;
if (write(fdindex, &index, sizeof(struct index)) != sizeof(struct index))
return -1;
}
bid_ent=bid_ent->next;
}
bid_ent=&first;
free(bid_ent->next);
close(fdindex);
return 0;
}